<?php

include 'database.php'; //数据库的配置信息
require 'lianjie.php';  // 数据库的操作函数
$con = lianjieshujuku($servername, $name, $passwd);//连接数据库

$mac = $_GET['mac'];
$username = $_GET['username'];
$kongshi = $_GET['kongshi'];
$kongwen = $_GET['kongwen'];
$jt = $_GET['jt'];
$pt = $_GET['pt'];
$mac_name = $_GET['mac_name'];
$path = "floweruser/" . $username . "/" . $mac;
$picpath = "floweruser/" . $username;

if (is_dir($path)) {
    echo "存在";
} else {
    mkdir($path, 0777, true);
}
if ($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "零食地点 file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists($picpath . "/" . $mac . ".jpg")) {
// echo $_FILES["file"]["name"] . " 已经存在. ";
        unlink("upload/" . $mac . ".jpg");
    }


    move_uploaded_file($_FILES["file"]["tmp_name"],
        $picpath . "/" . $mac . ".jpg");
    echo "储存在 in: " . $picpath . "/" . $mac . ".jpg";

}
//fname 增加
if (!mysqli_select_db($con, 'flower')) {
    die("选择数据库失败");
}
$req = mysqli_query($con, "INSERT INTO `fname` (`op`, `mode`, `kongshi`, `kongwen`, `jt`, `pt`, `at`, `mac`, `macname`, `atname`) VALUES ('0', '1', '$kongshi', '$kongwen', '$jt', '$pt', '#|#|#|#|#|#|#|#', '$mac', '$mac_name', '#|#|#|#|#|#|#|#')");
if ($req) {
    echo "fname成功";
}

//flowdate 增加
if (!mysqli_select_db($con, 'flowdate')) {
    die("选择数据库失败");
}
$req = mysqli_query($con, "CREATE TABLE `flowdate`.`$mac` ( `kongshi` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `kongwen` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `time` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d1` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d2` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d3` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d4` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d5` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d6` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d7` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `d8` VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ) ENGINE = InnoDB;");
if ($req) {
    echo "mac成功";
}

//user
if (!mysqli_select_db($con, 'floweruser')) {
    die("选择数据库失败");
}
$req = mysqli_query($con, "SELECT * from `user` WHERE `username`='$username'");
$jieguo = mysqli_fetch_array($req);
$oldmac = $jieguo['flowers'];
if($oldmac!="") {


    $newmac = $oldmac . "|" . $mac;
}
$newmac = $mac;
$req = mysqli_query($con, "UPDATE `user` SET `flowers`='$newmac' WHERE `username`='$username'");
if ($req) {
    echo 'user成功';
}
?>